package process_demo.review.interrupt;

import java.util.Scanner;
import java.util.concurrent.TimeUnit;

/**
 * @author haomin
 * @date 2022/09/09 18:52
 **/
public class Main {
    static class Mythread extends Thread{
        @Override
        public void run() {
            while (true){
                for (int i = 0; i < 1000; i++) {
                    System.out.println("我正在写代码");
                }

                if(interrupted()) {
                    System.out.println("休息前停下来");
                    break;
                }
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    System.out.println("休息中停下来");
                    break;
                }
                if(interrupted()) {
                    System.out.println("休息后停下来");
                    break;
                }
            }
            System.out.println("线程停下来了");
        }
    }

    public static void main(String[] args) {
        Mythread t = new Mythread();
        t.start();

        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();

        t.interrupt();

    }
}